package com.dnjn.happiness.oss.config;

import io.minio.MinioClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Data
@RefreshScope
@Configuration
@ConfigurationProperties(prefix = "minio")
public class MinioClientConfig {

    private String endpoint;
    private String publishHost;
    private String bucketName;

    private String accessKey;
    private String secretKey;

    public String getDownloadDomain() {
        return String.format("%s/%s", publishHost, bucketName);
    }
    /*@Bean("rootMinioClient")
    public MinioClient getDefaultMinioClient() {
        return MinioClient.builder()
                .endpoint(props.getEndpoint())
                .credentials(props.getRootUsername(), props.getRootPassword())
                .build();
    }*/

    @Primary
    @Bean("minioClient")
    public MinioClient getMinioClient() {
        return MinioClient.builder()
                .endpoint(endpoint)
                .credentials(accessKey, secretKey)
                .build();
    }
}
